<?php




if($argc < 2){

	exit("you should give a file that get from http://x.x.x.x/param.file.tgz \n");
}

$fileName=$argv[1];
if(!is_file($fileName)){

	exit("sorry file not exists");
}

$d0=array();
$d1=array();

$hFile = fopen($fileName,"rb");

//echo ftell($hFile)."\n";
//fseek($hFile,0,SEEK_END);
//echo filesize($fileName)."\n";
//echo ftell($hFile)."\n";

$fileSize = filesize($fileName);


//init 
for($i=33; $i<=127 ;$i++){

 $a=$i;

 if( $a+201 < 256){

 	 $d0[$a+201]=($a); //ord("A");

 }else{

 	$d0[$a-55]=($a);
 }

 $d1[$a+115]=($a);
}





$wFile=fopen("./param.ini","wb");
for($i=0;$i<$fileSize;$i++){
    	$key =fread($hFile,1);
    	
    	$j=ord($key);//base_convert($key,16,10);
    	//echo (int)$key."--".$j."--".ord($key)."@ ";
		if(($i % 2) == 0){
            if(array_key_exists($j,$d0)){
            	$value = $d0[$j];
            }else{

            	$value=0;
            }
			
		}else{

			if(array_key_exists($j,$d1)){
            	$value = $d1[$j];
            }else{

            	$value=0;
            }
		}


			if($i==164){

				echo "username:";
			}
			if($i>=164 && $i<180){

				echo chr($value);
			}
			if($i==180){

				echo "\npassword:";
			}
			if($i>=180 && $i<=196)
			echo chr($value);
		
		fwrite($wFile,chr($value));

}
echo "\n";

